PROCEDURE TForm4.TestShlWAPIPathIsSystemFolder(Sender : TObject);
VAR pathtotest : STRING;
VAR fileattributes : DWORD;
VAR apiretval : BOOL;
VAR newinfoline : STRING;
BEGIN
pathtotest := '';
fileattributes := 0;
apiretval := FALSE;
newinfoline := '';
pathtotest := 'C:\Windows\System32';
fileattributes := GetFileAttributes(PChar(pathtotest));
newinfoline := 'PathIsSystemFolder called with ' + pathtotest + ' (attributes: 0x' + IntToHex(fileattributes, 8) +
') and FILE_ATTRIBUTE_SYSTEM';
Memo1.Lines.Add(newinfoline);
fileattributes := FILE_ATTRIBUTE_SYSTEM;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
pathtotest := 'C:\Hello\World'; //Non-existent path !
fileattributes := GetFileAttributes(PChar(pathtotest));
newinfoline := 'PathIsSystemFolder called with ' + pathtotest + ' (attributes: 0x' + IntToHex(fileattributes, 8) +
') and 0';
Memo1.Lines.Add(newinfoline);
fileattributes := 0;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
pathtotest := 'C:\Windows\System32\Microsoft';
fileattributes := GetFileAttributes(PChar(pathtotest));
newinfoline := 'PathIsSystemFolder called with ' + pathtotest + ' (attributes: 0x' + IntToHex(fileattributes, 8) +
') and FILE_ATTRIBUTE_SYSTEM';
Memo1.Lines.Add(newinfoline);
fileattributes := FILE_ATTRIBUTE_SYSTEM;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
pathtotest := 'C:\Windows\System32\Microsoft';
fileattributes := GetFileAttributes(PChar(pathtotest));
newinfoline := 'PathIsSystemFolder called with ' + pathtotest + ' (attributes: 0x' + IntToHex(fileattributes, 8) +
') and 0';
Memo1.Lines.Add(newinfoline);
fileattributes := 0;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
pathtotest := 'C:\Windows\System32\ShlWAPI.dll'; //Call with file instead of folder
fileattributes := GetFileAttributes(PChar(pathtotest));
newinfoline := 'PathIsSystemFolder called with ' + pathtotest + ' (attributes: 0x' + IntToHex(fileattributes, 8) +
') and FILE_ATTRIBUTE_ARCHIVE';
Memo1.Lines.Add(newinfoline);
fileattributes := FILE_ATTRIBUTE_ARCHIVE;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
pathtotest := 'C:\Windows\System';
fileattributes := GetFileAttributes(PChar(pathtotest));
newinfoline := 'PathIsSystemFolder called with ' + pathtotest + ' (attributes: 0x' + IntToHex(fileattributes, 8) +
') and FILE_ATTRIBUTE_READONLY';
Memo1.Lines.Add(newinfoline);
fileattributes := FILE_ATTRIBUTE_READONLY;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
pathtotest := '';
newinfoline := 'PathIsSystemFolder called with an empty string ' +
' and FILE_ATTRIBUTE_SYSTEM OR FILE_ATTRIBUTE_DIRECTORY';
Memo1.Lines.Add(newinfoline);
fileattributes := FILE_ATTRIBUTE_SYSTEM OR FILE_ATTRIBUTE_DIRECTORY;
apiretval := PathIsSystemFolder(PChar(pathtotest), fileattributes);
IF apiretval THEN
newinfoline := 'TRUE'
ELSE
newinfoline := 'FALSE';
Memo1.Lines.Add(newinfoline);
Memo1.Lines.Add('');
END; |